package d0327;

import java.util.*;

    public class Homework {
        private static List<Student> data = new ArrayList<Student>();
        static class Student{
            private int id;
            private String name;
            private int score;

            public Student(int id, String name, int score){
                this.id = id;
                this.name = name;
                this.score = score;
            }
            public int getId() {
                return id;
            }
            public String getName() {
                return name;
            }
            public int getScore() {
                return score;
            }

            public String toString() {
                return "学号：" + id + ", 姓名：" + name  + ", 成绩：" + score ;
            }

            @Override
            public int hashCode() {
                return score;
            }
            public int compareTo(Student o) {
                if (getScore()>o.getScore()) {
                    return -1;
                }
                else if (getScore()<o.getScore()){
                    return 1;
                }
                else {
                    return 0;
                }
            }
        }
        public static void Sorce(){
            int j = 10;
            Random random = new Random();
            for (int i = 0;i < 68;++i){
                data.add(new Student(180201+i,"同学"+(i+j),random.nextInt(51)+50));
            }
        }
        public static void print(){
            Iterator<Student> iterator = data.iterator();
            while (iterator.hasNext()){
                Student next1 = iterator.next();
                int id = next1.getId();
                String name = next1.getName();
                int score = next1.getScore();
                System.out.println(id+name+score);
            }
        }

        public static void main(String[] args) {
            Homework homeWork2= new Homework();
            Sorce();
            Collections.sort(data,Student::compareTo);
            data.forEach(student -> System.out.println(student));
        }
    }

